package test7;

public class GirlFriendTest {
    public static void main(String[] args) {
        GirlFriend[] arr = new GirlFriend[4];

        GirlFriend gf1 = new GirlFriend("小红",18,"女","游泳");
        GirlFriend gf2 = new GirlFriend("小王",18,"女","跑步");
        GirlFriend gf3 = new GirlFriend("小徐",20,"女","跳绳");
        GirlFriend gf4 = new GirlFriend("小方",17,"女","画画");

        arr[0] = gf1;
        arr[1] = gf2;
        arr[2] = gf3;
        arr[3] = gf4;

        //求和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            sum+=gf.getAge();
        }
        
        //平均值
        int avg = sum/arr.length;
        
        //统计年龄比平均值大的有几个
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            //从数组 arr 中取出索引为 i 的 GirlFriend 对象，并将其引用赋值给变量 gf。
            // 这样，gf 就可以用来访问或操作这个对象的属性和方法了。
            if(gf.getAge()>avg){
                System.out.println(gf.getName()+","+gf.getAge()+","+gf.getGender()+","+gf.getHobby());
            }
        }
    }
}
